package com.senthink.gl.business.api.controller;

import com.senthink.gl.business.forgetpw.ForgetPasswordRequest;
import com.senthink.gl.business.forgetpw.ForgetPasswordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 重置密码Controller
 * @author yuanpeng@senthink.com
 * @data 2018-01-24 15:24
 */
@Api(tags = "重置密码Controller")
@Controller
public class ForgetPasswordController {

    @Autowired
    private ForgetPasswordService service;

    @ApiOperation(notes = "重置密码，校验是否能重置密码",value = "重置密码，校验是否能重置密码")
    @RequestMapping(value = "${uri.reset.password}", method = RequestMethod.GET)
    public ResponseEntity<?> forgetpw(String email, String mobile, String verifyCode) {
        return ResponseEntity.ok(service.forgetPw(email, mobile, verifyCode));
    }


    @ApiOperation(notes = "请求图形校验码",value = "请求图形校验码")
    @RequestMapping(value = "${uri.reset.verifyCode}", method = RequestMethod.GET)
    public ResponseEntity<?> verifyCode(HttpServletRequest request, HttpServletResponse response, String email, String mobile) {
        return ResponseEntity.ok(service.verifyCode(request, response, email, mobile));
    }

    @ApiOperation(notes = "校验验证码",value = "校验验证码")
    @RequestMapping(value = "${uri.reset.checkCode}", method = RequestMethod.GET)
    public ResponseEntity<?> checkCode(String email, String mobile, String code){
        return ResponseEntity.ok(service.checkCode(email, mobile, code));
    }

    @ApiOperation(notes = "校验用户是否存在以及获取验证码次数",value = "校验用户是否存在以及获取验证码次数")
    @RequestMapping(value = "${uri.reset.checkAccount}", method = RequestMethod.GET)
    public ResponseEntity<?> checkAccount(String email, String mobile){
        return ResponseEntity.ok(service.checkAccount(email, mobile));
    }

    @ApiOperation(notes = "重置密码",value = "重置密码")
    @RequestMapping(value = "${uri.reset.resetPassword}", method = RequestMethod.POST)
    public ResponseEntity<?> checkCode(@RequestBody @Validated(ForgetPasswordRequest.ResetPassword.class) ForgetPasswordRequest request){
        return ResponseEntity.ok(service.resetPw(request));
    }

}
